package com.lzw.d25bingso.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lzw.d25bingso.R;
import com.lzw.d25bingso.bean.Industry;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by lzw on 2017/5/17.
 */

public class IndustryAdapter  extends BaseAdapter{
    private Context context;
    private List<Industry> data;

    public IndustryAdapter(Context context, List<Industry> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        return data.size()>0?data.size():0;
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder ;
        if (convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.gv_item,parent,false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.tv.setText(data.get(position).getName());
        Picasso.with(context).load(data.get(position).getImgurl()).into(viewHolder.iv);
        return convertView;
    }

    static class ViewHolder{
        private ImageView iv;
        private TextView tv;

        public ViewHolder(View view) {
            iv = (ImageView) view.findViewById(R.id.iv_gv);
            tv = (TextView) view.findViewById(R.id.tv_gv);
        }
    }
}
